<?php
/**
 * 账单
 */
namespace App\Http\ControllersAdmin;

use App\Service\BillService;
use App\Validation\BillValidation;
use App\Validation\BillSearchValidation;

class BillController extends BaseController
{
	/**
	 * [indexAction 列表]
	 * @return [type] [description]
	 */
	public function indexAction()
	{
		$this->getUser();
		$raw = $this->validation(new BillSearchValidation, $this->request->getJsonRawBody());

		$data = BillService::getSearch($raw);
		$count = BillService::getSearch($raw, TRUE);

		$assign = [
			'total' => $count,
			'list'  => $data
		];
		return $this->echoJson($assign);
	}

	/**
	 * [createAction 创建]
	 * @return [type] [description]
	 */
	public function createAction()
	{
		$this->getUser();
		$raw = $this->validation(new BillValidation, $this->request->getJsonRawBody());
		$data = BillService::save($raw);
		return $this->echoJson('ok');
	}

	/**
	 * [detailAction 详情]
	 * @return [type] [description]
	 */
	public function detailAction()
	{
		$this->getUser();
		$id = $this->dispatcher->getParam('id');
		$data = BillService::getInfo($id);
		return $this->echoJson($data);
	}

	/**
	 * [updateAction 更新]
	 * @return [type] [description]
	 */
	public function updateAction()
	{
		$this->getUser();
		$raw = $this->validation(new BillValidation, $this->request->getJsonRawBody());
		$data = BillService::save($raw);
		return $this->echoJson('ok');
	}

	/**
	 * [deleteAction 删除]
	 * @return [type] [description]
	 */
	public function deleteAction()
	{
		$this->getUser();
		$id = $this->dispatcher->getParam('id');
		$data = BillService::forever($id);
		return $this->echoJson('ok');
	}
}